***************************************************************
**This will test for rank similarity across treatment and 
**control observations;
***************************************************************

* This do file is based on the replication files created by Frandsen and Lefgren and published here: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/P8EZKH

# delimit;

program drop _all;
clear all;
capture log close;
set mat 800;
set more off;


putexcel set "$output\AppendixTable4", modify;

putexcel A1=("Rank Similarity") B2=("Full-cost program") D2=("Reduced-cost program") ///
B3=("Test statistic") C3=("P-value") D3=("Test statistic") E3=("P-value") ///
A5=("Baseline Test Score") A7=("1(BL missing)") A9=("1(Student male)") A11=("Student's Age") ///
A13=("1(Male teacher)") A15=("Teacher's Age") A17=("Teacher's Experience") A19=("Years of Education") ///
A21=("School's Enrollment") A23=("Pupil-Teacher-Ratio") A25=("PLE Pass Rate") A27=("Number of Teachers");


capture program drop FL_ranktest;
do "$ados\ranktest.ado";
do "$ados\abadiels.ado";

use "$dir\DataSCLB", clear;

  
**********************FULL-COST PROGRAM******************************************

keep if Study_Arm!=1;

keep Pupil_blind MT_Program CCT_Program Study_Arm EL_EGRA_PCA_Index L_BLabil Dmiss_BL Dmale Lage DTeachMale  LTeachAge LTeachExper LTeachEduc Lenrol LPTR LPLEPassRate LNTeachers;

**Formal tests.;

local vars L_BLabil Dmiss_BL Dmale Lage DTeachMale  LTeachAge LTeachExper LTeachEduc Lenrol LPTR LPLEPassRate LNTeachers;

local nrow=5;
foreach x of local vars{;
FL_ranktest EL_EGRA_PCA_Index MT_Program MT_Program `x';
local delta=string(r(delta),"%5.2f");
local pval=string(r(pval),"%5.2f");
putexcel B`nrow'=(`delta');
putexcel C`nrow'=(`pval');

local nrow=`nrow'+2;
};

**********************REDUCED-COST PROGRAM******************************************


use "$dir\DataSCLB", clear

  
**Let's keep only those observations that have all of the data
**we need.;

keep if Study_Arm!=2;

keep Pupil_blind MT_Program CCT_Program Study_Arm EL_EGRA_PCA_Index L_BLabil Dmiss_BL Dmale Lage DTeachMale  LTeachAge LTeachExper LTeachEduc Lenrol LPTR LPLEPassRate LNTeachers;

**Formal tests.;

local vars L_BLabil Dmiss_BL Dmale Lage DTeachMale  LTeachAge LTeachExper LTeachEduc Lenrol LPTR LPLEPassRate LNTeachers;

local nrow=5;
foreach x of local vars{;
FL_ranktest EL_EGRA_PCA_Index CCT_Program CCT_Program `x';

local delta=string(r(delta),"%5.2f");
local pval=string(r(pval),"%5.2f");
putexcel D`nrow'=(`delta');
putexcel E`nrow'=(`pval');

local nrow=`nrow'+2;
};
  
